package com.shuigu.common.utils.resource;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class ResourceUtil {

    /**
     * 获取 classpath 下的资源
     * @param path 相对 classpath 的路径，例如 "prohibitedWord/Vocabulary/text.txt"
     * @return Resource 对象
     */
    public static Resource getResource(String path) {
        return new ClassPathResource(path);
    }

    /**
     * 获取资源文件内容
     * @param path 相对 classpath 的路径
     * @return 文件内容字符串
     */
    public static String getResourceContent(String path) {
        try {
            Resource resource = new ClassPathResource(path);
            return new String(resource.getInputStream().readAllBytes());
        } catch (Exception e) {
            throw new RuntimeException("无法读取资源文件：" + path, e);
        }
    }
}
